home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / QUIZGAM.DIR / 00179_Script_GAME HANDLERS < prev    next >
Text File  |  1996-03-19  |  8KB  |  238 lines

  1. -- -----------------------------------------------------------------------------
  2. -- handler displayPartOfQuestionOfTile shows an item of a question in a tile
  3.  
  4. on displayPartOfQuestionOfTile part,aQuestion,aSprite
  5.   global spriteNrOfFirstTileOffset,QCastName,ACastName
  6.   
  7.   displayCastInSprite (part&aQuestion),aSprite
  8.   
  9. end
  10.  
  11.  
  12. -- -----------------------------------------------------------------------------
  13. -- handler processAnswer gets called after user clicks an answer
  14.  
  15. on processAnswer aQuestion,clickV,nrOfAnswers
  16.   global wrongAnswer,feedbackSprite
  17.   
  18.   set currSprite   = the clickOn
  19.   set currCastName = the name of cast (the castNum of sprite currSprite)
  20.   set currQuestion = getQuestionNumberFromCastName(currCastName)
  21.   
  22.   set anAnswer = getAnswerClicked(clickV,currSprite,nrOfAnswers)
  23.   
  24.   -- 1) CORRECT ANSWER
  25.   if anAnswer = getCorrectAnswer(value(currQuestion)) then
  26.     
  27.     -- get the feedbacktext for this question
  28.     showFeedBack currQuestion,currSprite
  29.     
  30.     -- 1 becomes 001, 10 becomes 010 etc (to match names of soundfiles)
  31.     set newNumber = addZeros(currQuestion)
  32.     playSound "Answr" & newNumber & ".AIF"
  33.     
  34.     -- show the next question for this tile
  35.     showNextQuestionForTile currSprite
  36.     
  37.     -- check if game is over
  38.     if checkGameOver() then
  39.       go the frame + 1
  40.       -- go to the correct animation after the game
  41.       set gameNr = getGameNr()
  42.       restartGame "Animation"&gameNr
  43.     end if
  44.     
  45.     -- 2) WRONG ANSWER  
  46.   else
  47.     sound stop 1
  48.     set the visible of sprite feedbackSprite = FALSE
  49.     playSound wrongAnswer
  50.   end if
  51.   
  52. end
  53.  
  54.  
  55. -- -----------------------------------------------------------------------------
  56. -- handler restartGame resets all sprits & movies to the specified frame containing 
  57. -- an animation
  58.  
  59. on restartGame nextFrame
  60.   global gameNr,spriteNrOfFirstTileOffset,spriteNrOfLastTile
  61.   
  62.   setSpritesVisibility (spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,TRUE
  63.   -- set puppets of Q & A to FALSE to prevent them showing during animation
  64.   resetPuppetSprites
  65.   go frame nextFrame
  66.   set gameNr = GameNr + 1
  67.   
  68. end
  69.  
  70.  
  71. -- -----------------------------------------------------------------------------
  72. -- handler resetPuppetSprites sets all puppetSprites of Q & A to FALSE 
  73.  
  74. on resetPuppetSprites
  75.   global spriteNrOfFirstTileOffset,coloredTileOffset
  76.   
  77.   set firstSprite =  coloredTileOffset + 1
  78.   set lastSprite  = spriteNrOfFirstTileOffset + (2 * spriteNrOfFirstTileOffset) + 1
  79.   
  80.   setPuppets firstSprite,lastSprite,FALSE
  81.   
  82. end
  83.  
  84.  
  85. -- -----------------------------------------------------------------------------
  86. -- handler getQuestionNumberFromCastName returns the question number from a castName
  87. -- since casts are named "Q"(xx>,"A"<xx> and "F"<xx> this returns only the nr
  88.  
  89. on getQuestionNumberFromCastName aCastName
  90.   set lastChar = the number of chars in aCastName
  91.   return char(2) to (lastChar) of aCastName
  92. end
  93.  
  94.  
  95. -- -----------------------------------------------------------------------------
  96. -- handler allQuestionsAnswered returns TRUE if all questions in a sprite are answered
  97.  
  98. on allQuestionsAnswered aQuestion
  99.   global questionIndex,questionNumbers,nrOfQuestionsPerTile
  100.   
  101.   set qanswered = getItemFromLineFromVar(questionIndex,aQuestion,questionNumbers)
  102.   return value(qanswered) = (nrOfQuestionsPerTile + 1)
  103.   
  104. end
  105.  
  106.  
  107. -- -----------------------------------------------------------------------------
  108. -- handler showFeedBack displays feedback for question aQuestion
  109.  
  110. on showFeedBack aQuestion,aSprite
  111.   global feedBackSprite
  112.   
  113.   -- get the castMember containing feedBack for this Q
  114.   set feedBack = "F" & aQuestion
  115.   --  set the feedBackSprite to the position of the answer sprite
  116.   set feedBackSpritePosition = getSpritePosition(aSprite)
  117.   set the visible of sprite feedBackSprite = FALSE
  118.   setSpriteToPosition feedBackSprite,feedBackSpritePosition
  119.   -- show the feedBack cast on stage
  120.   displayCastInSprite feedBack,feedBackSprite
  121.   set the visible of sprite feedBackSprite = TRUE
  122.   
  123. end
  124.  
  125.  
  126. -- -----------------------------------------------------------------------------
  127. -- handler displayCastInSprite displays cast aCastName in sprite aSprite
  128.  
  129. on displayCastInSprite aCastName,aSprite
  130.   set the castNum of sprite aSprite to the number of cast aCastName
  131.   updateStage
  132. end
  133.  
  134. -- -----------------------------------------------------------------------------
  135. -- handler addZeros converts 1 into 001, 10 into 010 etc. Returns a string
  136.  
  137. on addZeros aNumber
  138.   if aNumber < 10 then
  139.     set aNumber = "00"&aNumber
  140.   else
  141.     if (aNumber > 9) AND (aNumber < 100) then
  142.       set anumber = "0"&aNumber
  143.     end if
  144.   end if
  145.   return aNumber
  146. end
  147.  
  148.  
  149. -- -----------------------------------------------------------------------------
  150. -- handler showNextQuestionForTile updates the index so it points to the next question
  151.  
  152. on showNextQuestionForTile aSprite
  153.   global questionNumbers,nrOfQuestionsPerTile,spriteNrOfFirstTileOffset,questionIndex
  154.   
  155.   --  get the tile number (1 - 9) from the sprite the tile is in (3 - 20)
  156.   set currTile = (aSprite - spriteNrOfFirstTileOffset) / 2
  157.   
  158.   --  get the index that indicates the next question & update it so it points to next q
  159.   set index = getItemFromLineFromVar(questionIndex,currTile,questionNumbers)
  160.   set index = integer(index + 1)
  161.   set questionNumbers = setItemOfLineOfVartoValue(questionIndex,currTile,questionNumbers,index)
  162.   
  163.   -- Not all questions are answered
  164.   if (index <= nrOfQuestionsPerTile) then
  165.     -- hide the old feedBack
  166.     setColoredTile currTile,aSprite
  167.     displayCastInSprite "Q & A Placeholder (white)"(ASPRITE)
  168.     -- arguments: atile, questionsprite, answersprite
  169.     set qSprite = aSprite - 1
  170.     set aSprite = aSprite
  171.     getQuestionForTile currTile,qSprite,aSprite
  172.   else  -- all questions are answered
  173.     -- hide the sprite now containing feedback
  174.     setSpriteVisibility aSprite,FALSE
  175.     showPicture currTile
  176.   end if
  177.   
  178. end
  179.  
  180. -- -----------------------------------------------------------------------------
  181. -- handler setColoredTile shows a colored tile to indicate the nr of q's answered
  182. -- so far
  183.  
  184. on setColoredTile currTile,aSprite
  185.   global coloredTileOffset,questionIndex,questionNumbers,spriteNrOfFirstTileOffset
  186.   
  187.   set nrOfQuestionsAnswered = getItemFromLineFromVar(questionIndex,currTile,questionNumbers)
  188.   set coloredTileSprite = ((aSprite - spriteNrOfFirstTileOffset) / 2) + coloredTileOffset
  189.   displayCastInSprite ("coloredTile"&& currTile && nrOfQuestionsAnswered),coloredTileSprite
  190.   
  191. end
  192.  
  193. -- -----------------------------------------------------------------------------
  194. -- handler showPicture shows the background behind a tile
  195.  
  196. on showPicture aTile
  197.   global backgroundTileOffset
  198.   
  199.   setSpriteVisibility (aTile + backgroundTileOffset),TRUE
  200.   
  201. end
  202.  
  203. -- -----------------------------------------------------------------------------
  204. -- handler checkGameOver returns TRUE if all tiles are turned into pictures
  205.  
  206. on checkGameOver
  207.   global questionIndex,questionNumbers,nrOfTiles,questionIndex,nrOfQuestionsPerTile
  208.   
  209.   -- check all tiles...
  210.   repeat with currentTile = 1 to nrOfTiles
  211.     
  212.     -- if there's one not answered, stop checking & return FALSE
  213.     if (NOT( allQuestionsAnswered(currentTile) )) then
  214.       set checkGameOver = FALSE
  215.       exit repeat
  216.     else
  217.       set checkGameOver = TRUE
  218.     end if
  219.   end repeat
  220.   
  221.   return checkGameOver
  222.   
  223. end
  224.  
  225.  
  226. -- -----------------------------------------------------------------------------
  227. -- handler playSound plays AIFF sound file aFile with puppetSound
  228.  
  229. on playSound aFile
  230.   global soundFolder,soundHolder
  231.   
  232.   --  copy the AIFF file into a placeHolder in the cast so we can use puppetSound
  233.   set delimiter = getPathDelimiter()
  234.   swapSoundFile soundFolder & delimiter & aFile
  235.   puppetSound soundHolder
  236.   updateStage
  237.   waitVoiceQGame 1
  238. end